<?php
namespace app\commission\controller;
use app\ApiRest;
use think\App;
use app\commission\model\Cash as Model;
use app\commission\model\Water;
use app\commission\model\Wallet;

use think\facade\Cache;
use think\facade\Db;

class IndexCash extends ApiRest
{

    protected $model;

    protected $water_model;

    protected $wallet_model;

    public function __construct(App $app) {
        parent::__construct($app);
        $this->model        = new Model();

        $this->water_model  = new Water();

        $this->wallet_model = new Wallet();
    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-23 15:05
     * @功能说明:个人中心
     */
    public function userInfo(){

        $input = $this->_input;
        //初始化一下
        $this->model->initData(['user_id'=>$this->getUserId(),'uniacid'=>$this->_uniacid]);
        //余额
        $data['user_info']['total_price'] = $this->model->where(['user_id'=>$this->getUserId(),'uniacid'=>$this->_uniacid])->value('total_cash');
        //累计返佣
        $cash = $this->water_model->where(['user_id'=>$this->getUserId(),'status'=>2])->sum('cash');

        $data['user_info']['cash'] = round($cash,2);

        if($input['type']==1){
            //返佣记录
            $dis = [
                'user_id' => $this->getUserId(),

                'status'  => 2

            ];
            $data['list'] = $this->water_model->waterList($dis,10);

        }else{
            //提现记录
            $data['list'] = $this->wallet_model->walletList(['user_id'=>$this->getUserId()],10);

        }
        return $this->success($data);
    }






}
